package com.agile.major.service.impl;

import com.agile.major.domain.BaseMajor;
import com.agile.major.domain.RecruitStudent;
import com.agile.major.repository.BaseMajorRepository;
import com.agile.major.repository.RecruitStudentRepository;
import com.agile.major.service.RecruitStudentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * Service Implementation for managing RecruitStudent.
 */
@Service
@Transactional
public class RecruitStudentServiceImpl implements RecruitStudentService{

    private final Logger log = LoggerFactory.getLogger(RecruitStudentServiceImpl.class);

    private final RecruitStudentRepository recruitStudentRepository;
    private  BaseMajorRepository baseMajorRepository;

    public RecruitStudentServiceImpl(
        RecruitStudentRepository recruitStudentRepository,
        BaseMajorRepository baseMajorRepository
    ) {
        this.recruitStudentRepository = recruitStudentRepository;
        this.baseMajorRepository=baseMajorRepository;
    }

    /**
     * Save a recruitStudent.
     *
     * @param recruitStudent the entity to save
     * @return the persisted entity
     */
    @Override
    public RecruitStudent save(RecruitStudent recruitStudent) {
        log.debug("Request to save RecruitStudent : {}", recruitStudent);
        return recruitStudentRepository.save(recruitStudent);
    }

    /**
     *  Get all the recruitStudents.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<RecruitStudent> findAll(Pageable pageable) {
        log.debug("Request to get all RecruitStudents");
        return recruitStudentRepository.findAll(pageable);
    }

    /**
     *  Get one recruitStudent by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public RecruitStudent findOne(Long id) {
        log.debug("Request to get RecruitStudent : {}", id);
        return recruitStudentRepository.findOne(id);
    }

    /**
     *  Delete the  recruitStudent by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete RecruitStudent : {}", id);
        recruitStudentRepository.delete(id);
    }

    @Override
    public List<RecruitStudent> getRecruitStuByMajorAndYear(Long id, String year) {
        BaseMajor major = baseMajorRepository.findOne(id);
        if (major == null) {
            log.debug("Request to get RecruitStudent : {}", major);
        }
        return recruitStudentRepository.findRecruitStudentsByBaseMajorAndDataYear(major,year);
    }

}
